home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / text / edit / tecoc-146.lha / err.c < prev    next >
C/C++ Source or Header  |  1991-07-05  |  10KB  |  331 lines

  1. /*****************************************************************************
  2.  
  3.     ErrChr(), ErrMsg(), ErrStr(), ErrUTC(), ErrVrb()
  4.  
  5.     These functions display TECO's error messages.
  6.  
  7.     ErrChr    display a message that contains a special character
  8.     ErrMsg    display a message given the message number
  9.     ErrStr    display a message that contains a special string
  10.     ErrUTC    display UTC or UTM based on macro stack depth
  11.     ErrVrb    display the verbose form of an error message
  12.  
  13. *****************************************************************************/
  14.  
  15. #include "zport.h"        /* define portability identifiers */
  16. #include "tecoc.h"        /* define general identifiers */
  17. #include "defext.h"        /* define external global variables */
  18. #include "deferr.h"        /* define error message codes */
  19. #include "dchars.h"        /* define identifiers for characters */
  20.  
  21. #include <string.h>        /* prototype for strlen() */
  22.  
  23. #if USE_PROTOTYPES
  24. static    VVOID    ErrDsp(WORD ErrNum, unsigned char *ELine);
  25. static    VVOID    ToErr(unsigned char Charac, charptr *PtrPtr);
  26. #endif
  27.  
  28.  
  29. /****
  30.    IMPORTANT: if you change this list,  you must also change DEFERR.H,
  31.    TECOC.RNH and VRBMSG.H !!!
  32. ****/
  33.  
  34. static char *Errors[] = {
  35. /*  0*/  "ARG   Improper arguments",
  36. /*  1*/  "BNI   > not in iteration",
  37. /*  2*/  "DTB   Delete too big",
  38. /*  3*/  "FNF   File not found \"%s\"",
  39. /*  4*/  "ICE   Illegal ^E command in search argument",
  40. /*  5*/  "IEC   Illegal character \"%s\" after E",
  41. /*  6*/  "IFC   Illegal character \"%s\" after F",
  42. /*  7*/  "IIA   Illegal insert argument",
  43. /*  8*/  "ILL   Illegal command \"%s\"",
  44. /*  9*/  "ILN   Illegal number",
  45. /* 10*/  "IPA   Negative or 0 argument to P",
  46. /* 11*/  "IQC   Illegal \" character",
  47. /* 12*/  "IQN   Illegal Q-register name \"%s\"",
  48. /* 13*/  "IRA   Illegal radix argument to ^R",
  49. /* 14*/  "ISA   Illegal search argument",
  50. /* 15*/  "ISS   Illegal search string",
  51. /* 16*/  "IUC   Illegal character \"%s\" following ^",
  52. /* 17*/  "MAP   Missing '",
  53. /* 18*/  "MEM   Memory overflow",
  54. /* 19*/  "NAB   No argument before ^_ ",
  55. /* 20*/  "NAC   No argument before ,",
  56. /* 21*/  "NAE   No argument before =",
  57. /* 22*/  "NAP   No argument before )",
  58. /* 23*/  "NAQ   No argument before \"",
  59. /* 24*/  "NAS   No argument before ;",
  60. /* 25*/  "NAU   No argument before U",
  61. /* 26*/  "NCA   Negative argument to ,",
  62. /* 27*/  "NFI   No file for input",
  63. /* 28*/  "NFO   No file for output",
  64. /* 29*/  "NYA   Numeric argument with Y",
  65. /* 30*/  "NYI   Not yet implemented",
  66. /* 31*/  "OFO   Output file already open",
  67. /* 32*/  "PDO   Push-down list overflow",
  68. /* 33*/  "PES   Attempt to pop an empty stack",
  69. /* 34*/  "POP   Attempt to move pointer off page with \"%s\"",
  70. /* 35*/  "SNI   ; not in iteration",
  71. /* 36*/  "SRH   Search failure \"%s\"",
  72. /* 37*/  "STL   String too long",
  73. /* 38*/  "TAG   Missing tag !%s!",
  74. /* 39*/  "UTC   Unterminated command",
  75. /* 40*/  "UTM   Unterminated macro",
  76. /* 41*/  "XAB   Execution aborted",
  77. /* 42*/  "YCA   Y command aborted",
  78. /* 43*/  "IFE   ill-formed numeric expression",
  79. /* 44*/  "SYS   %s",
  80. /* 45*/  "UCD   unable to close and delete output file %s",
  81. /* 46*/  "UCI   unable to close input file",
  82. /* 47*/  "UCO   unable to close output file",
  83. /* 48*/  "UFI   unable to open file %s for input",
  84. /* 49*/  "UFO   unable to open file %s for output",
  85. /* 50*/  "URC   unable to read character from terminal",
  86. /* 51*/  "URE   unable to read TECO command file",
  87. /* 52*/  "URL   unable to read line from input file",
  88. /* 53*/  "UWL   unable to write line to output file"
  89. };
  90.  
  91.  
  92. /*****************************************************************************
  93.  
  94.     ErrUTC()
  95.  
  96.     Simply call ErrMsg with either ERR_UTC (unterminated command) or
  97. ERR_UTM (unterminated macro) depending on whether we're in a macro or not.
  98.  
  99. *****************************************************************************/
  100.  
  101. VVOID ErrUTC()
  102. {
  103.     ErrMsg((MStTop < 0) ? ERR_UTC : ERR_UTM);
  104. }
  105.  
  106.  
  107. /*****************************************************************************
  108.  
  109.     ErrVrb()
  110.  
  111.     This function displays the verbose form of an error message.
  112. The verbose form is a short paragraph explaining the error condition in
  113. some detail.  This function is called from ErrDsp when the least significant
  114. two bits of the EH flag are set to 3,  or from FrstCh when the user types
  115. a / immediately after receiving a short error message.
  116.     Verbose explanations of error messages are stored in the HELP system
  117. so that they can be accessed using the HELP command.  Therefore this function
  118. calls ZHelp to display the verbose messages.
  119.  
  120. *****************************************************************************/
  121.  
  122. VVOID ErrVrb(ErrNum)        /* display verbose error message */
  123. WORD ErrNum;            /* error message number */
  124. {
  125.     DBGFEN(3,"ErrVrb",NULL);
  126.     ZVrbos(ErrNum, Errors[ErrNum]);
  127.     DBGFEX(3,DbgFNm,NULL);
  128. }
  129.  
  130.  
  131. /*****************************************************************************
  132.  
  133.     ErrDsp()
  134.  
  135.     This function displays a TECO error message on the terminal screen.
  136. This function is passed the number of the error message and the text of the
  137. error message.
  138.     The EH flag controls how verbose the error message will be.  The two
  139. least significant bits of the EH flag control how verbose the error message
  140. is.  The third bit (mask is EH_COMMAND) causes the erroneous command string up
  141. to and including the erroneous command to be displayed.
  142.     The low two bits of EH have the following meanings:
  143.  
  144.     0    same as 2
  145.     1    only the three letter code is output
  146.     2    three letter code and one-line error message
  147.     3    three letter code, one-lien message and paragraph
  148.  
  149. *****************************************************************************/
  150.  
  151.  
  152. static VVOID ErrDsp(ErrNum, ELine)
  153. WORD ErrNum;            /* the error number */
  154. unsigned char *ELine;        /* error message text */
  155. {
  156.     WORD HlpLvl;
  157.     ptrdiff_t lenn;
  158.  
  159.     HlpLvl = (EhFlag & 3) ? (EhFlag & 3) : 2;
  160.  
  161.     lenn = (HlpLvl < 2) ? 4 : strlen(ELine);
  162.     ZDspBf(ELine, lenn);
  163.  
  164.     if (HlpLvl == 3) {            /* if paragraph */
  165.         ErrVrb(ErrNum);            /* display paragraph */
  166.     }
  167.  
  168.     ZDspBf("\r\n", 2);
  169.     if (EhFlag & EH_COMMAND) {    /* if error string display is on */
  170.         TypESt();
  171.     }
  172.     LstErr = ErrNum;
  173. }
  174.  
  175.  
  176. /*****************************************************************************
  177.  
  178.     ToErr()
  179.  
  180.     Given a character and a buffer pointer,  this function puts the
  181. displayable representation for the character into the buffer and updates
  182. the buffer position.  For most characters,  the displayable representation
  183. is the character itself.
  184.  
  185. *****************************************************************************/
  186.  
  187. static VVOID ToErr(Charac, PtrPtr)
  188. unsigned char Charac;
  189. charptr *PtrPtr;
  190. {
  191.     char SBuf[5];
  192.     char *SPtr;
  193.     size_t SLen;
  194.  
  195.     switch (Charac) {
  196.         case TABCHR:    SPtr = "<TAB>";    SLen = 5; break;
  197.         case LINEFD:    SPtr = "<LF>";    SLen = 4; break;
  198.         case VRTTAB:    SPtr = "<VT>";    SLen = 4; break;
  199.         case FORMFD:    SPtr = "<FF>";    SLen = 4; break;
  200.         case CRETRN:    SPtr = "<CR>";    SLen = 4; break;
  201.         case ESCAPE:    SPtr = "<ESC>";    SLen = 5; break;
  202.         case '\0':        SPtr = "<NUL>";    SLen = 5; break;
  203.         default:        if (Charac >= DELETE) {
  204.                     SPtr = SBuf;
  205.                     MakDBf((LONG)Charac, 16);
  206.                     SLen = (size_t) (DBfPtr - DBfBeg);
  207.                     SBuf[0] = '[';
  208.                     MEMMOVE(&SBuf[1], DBfBeg, SLen);
  209.                     SBuf[++SLen] = ']';
  210.                     ++SLen;
  211.                 } else if (Charac < SPACE) {
  212.                     SPtr = SBuf;
  213.                     MEMMOVE(SBuf, "<^x>", 4);
  214.                     SBuf[2] = Charac + '@';
  215.                     SLen = 4;
  216.                 } else {
  217.                     SPtr = (char *)&Charac;
  218.                     SLen = 1;
  219.                 }
  220.                 break;
  221.     }
  222.     MEMMOVE(*PtrPtr, SPtr, SLen);
  223.     *PtrPtr += SLen;
  224. }
  225.  
  226.  
  227. /*****************************************************************************
  228. *****************************************************************************/
  229.  
  230. VVOID ErrChr(ErrNum, EChr)    /* display error message with character arg */
  231. WORD ErrNum;            /* the error number */
  232. unsigned char EChr;        /* character to imbed in message */
  233. {
  234.     char *TmpPtr;
  235.     unsigned char ErrBuf[ERBFSIZ];
  236.     charptr    EPtr = ErrBuf;
  237.  
  238.     *EPtr++ = '?';
  239.     TmpPtr = Errors[ErrNum];
  240.     while (*TmpPtr != '%') {    /* copy up to "%" */
  241.         *EPtr++ = *TmpPtr++;
  242.     }
  243.     ToErr(EChr, &EPtr);        /* copy the %c character */
  244.     TmpPtr++;            /* skip % */
  245.     TmpPtr++;            /* skip c */
  246.     while (*TmpPtr) {        /* copy rest of string */
  247.         *EPtr++ = *TmpPtr++;
  248.     }
  249.     *EPtr = '\0';
  250.     ErrDsp(ErrNum, ErrBuf);
  251. }
  252.  
  253.  
  254. /*****************************************************************************
  255. *****************************************************************************/
  256.  
  257. VVOID ErrMsg(ErrNum)        /* display error message */
  258. WORD ErrNum;            /* the error number */
  259. {
  260.     char *TmpPtr;
  261.     unsigned char ErrBuf[ERBFSIZ];
  262.     charptr EPtr = ErrBuf;
  263.  
  264.     *EPtr++ = '?';
  265.     TmpPtr = Errors[ErrNum];
  266.     while (*TmpPtr) {        /* copy rest of string */
  267.         *EPtr++ = *TmpPtr++;
  268.     }
  269.     *EPtr = '\0';
  270.     ErrDsp(ErrNum, ErrBuf);
  271. }
  272.  
  273.  
  274. /*****************************************************************************
  275. *****************************************************************************/
  276.  
  277. VVOID ErrStr(ErrNum, EStr)    /* display error message with string arg */
  278. WORD ErrNum;            /* the error number */
  279. char *EStr;            /* string to imbed in message */
  280. {
  281.     char *TmpPtr;
  282.     unsigned char ErrBuf[ERBFSIZ];
  283.     charptr EPtr = ErrBuf;
  284.  
  285.     *EPtr++ = '?';
  286.     TmpPtr = Errors[ErrNum];
  287.     while (*TmpPtr != '%') {    /* copy up to "%" */
  288.         *EPtr++ = *TmpPtr++;
  289.     }
  290.     while (*EStr) {            /* copy %s string */
  291.         ToErr((unsigned char)*EStr++, &EPtr);
  292.     }
  293.     TmpPtr++;            /* skip % */
  294.     TmpPtr++;            /* skip s */
  295.     while (*TmpPtr) {        /* copy rest of string */
  296.         *EPtr++ = *TmpPtr++;
  297.     }
  298.     *EPtr = '\0';
  299.     ErrDsp(ErrNum, ErrBuf);
  300. }
  301.  
  302.  
  303. /*****************************************************************************
  304. *****************************************************************************/
  305.  
  306. VVOID ErrPSt(ErrNum, EBeg, EEnd) /* display error message with string arg */
  307. WORD ErrNum;            /* the error number */
  308. charptr EBeg;            /* string to imbed in message */
  309. charptr EEnd;            /* ptr to char after last char */
  310. {
  311.     char *TmpPtr;
  312.     unsigned char ErrBuf[ERBFSIZ];
  313.     charptr EPtr = ErrBuf;
  314.  
  315.     *EPtr++ = '?';
  316.     TmpPtr = Errors[ErrNum];
  317.     while (*TmpPtr != '%') {    /* copy up to "%" */
  318.         *EPtr++ = *TmpPtr++;
  319.     }
  320.     while (EBeg < EEnd) {        /* copy %s string */
  321.         ToErr(*EBeg++, &EPtr);
  322.     }
  323.     TmpPtr++;            /* skip % */
  324.     TmpPtr++;            /* skip s */
  325.     while (*TmpPtr) {        /* copy rest of string */
  326.         *EPtr++ = *TmpPtr++;
  327.     }
  328.     *EPtr = '\0';
  329.     ErrDsp(ErrNum, ErrBuf);
  330. }
  331.